//
//  UITextField+JTExtension.m
//  百思不得姐
//
//  Created by Robin Zhang on 2016/12/23.
//  Copyright © 2016年 BeiJingWangDianJieTong. All rights reserved.
//

#import "UITextField+JTExtension.h"

static NSString *const JTPlaceholderColorKeyPath = @"placeholderLabel.textColor";

@implementation UITextField (JTExtension)

- (void)setJt_placeholderColor:(UIColor *)jt_placeholderColor {
    
    // 1.提前设置占位文字，目的：提前创建placeholderLabel
    if (!self.placeholder.length) {
        
        [self setPlaceholder:@" "];
        [self setPlaceholder:nil];
    }
    
    // 2.回复到默认的占位颜色
    if (!jt_placeholderColor) {
        
        jt_placeholderColor = [UIColor colorWithRed:0 green:0 blue:0.0980392 alpha:0.22];
    }
    
    // 3.设置占位文字颜色
    [self setValue:jt_placeholderColor forKeyPath:JTPlaceholderColorKeyPath];
}

- (UIColor *)jt_placeholderColor {
    
    return [self valueForKeyPath:JTPlaceholderColorKeyPath];
}

@end
